﻿using System;
using System.Collections.Generic;
using System.IO;
using LumenWorks.Framework.IO.Csv;

namespace BlackBox
{
    public class CsvParser
    {
        public static IList<AnalysisData> HydrateAnalyses(string filePath)
        {
            var analyses = new List<AnalysisData>();
            using (var csv = new CsvReader( new StreamReader( filePath ), false ))
            {
                var analysis = new AnalysisData();
                while (csv.ReadNextRecord())
                {
                    analysis.NewsId = Int32.Parse( csv[0] );
                    analysis.MatchingNewsId = Int32.Parse( csv[1] );
                    analysis.PriceAtEvent = Decimal.Parse( csv[2] );
                    analysis.ProjectedChangePercentage[MinuteInterval.One] = Decimal.Parse( csv[3] );
                    analysis.ProjectedChangePercentage[MinuteInterval.Three] = Decimal.Parse( csv[4] );
                    analysis.ProjectedChangePercentage[MinuteInterval.Five] = Decimal.Parse( csv[5] );
                    analysis.ProjectedChangePercentage[MinuteInterval.Ten] = Decimal.Parse( csv[6] );
                    analysis.ProjectedChangePercentage[MinuteInterval.Twenty] = Decimal.Parse( csv[7] );
                    analysis.ProjectedChangePercentage[MinuteInterval.FortyFive] = Decimal.Parse( csv[8] );
                    analysis.ActualChangePercentage[MinuteInterval.One] = Decimal.Parse( csv[9] );
                    analysis.ActualChangePercentage[MinuteInterval.Three] = Decimal.Parse( csv[10] );
                    analysis.ActualChangePercentage[MinuteInterval.Five] = Decimal.Parse( csv[11] );
                    analysis.ActualChangePercentage[MinuteInterval.Ten] = Decimal.Parse( csv[12] );
                    analysis.ActualChangePercentage[MinuteInterval.Twenty] = Decimal.Parse( csv[13] );
                    analysis.ActualChangePercentage[MinuteInterval.FortyFive] = Decimal.Parse( csv[14] );
                    analyses.Add( analysis );
                }
            }
            return analyses;
        }
    }
}
